home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / copyd11.zip / WSSCOPYD.C < prev    next >
C/C++ Source or Header  |  1992-12-06  |  39KB  |  1,379 lines

  1. #include <stdio.h>
  2. #include <bios.h>
  3. #include <conio.h>
  4. #include <dir.h>
  5. #include <dos.h>
  6. #include <io.h>
  7. #include <mem.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <ctype.h>
  11. #include <alloc.h>
  12.  
  13. #ifdef toupper
  14.     #undef toupper        /* don't want a macro version with side effects */
  15. #endif
  16.  
  17. /******************************  Warning !!!! ******************************
  18.  
  19.     This program uses writes to absolute sectors for copying and can format
  20.     disk tracks.  If you make changes, be sure that you know what you are
  21.     doing.  In particular, note that if a secondary floppy controller is in
  22.     use, the drive numbers used by int 13h for drives other than A: and B:
  23.     depend on the device driver used to access that controller.  On my system,
  24.     the two floppies on my secondary controller are H: and I:, yet they respond
  25.     as 4 and 5 to INT 13h.
  26.  
  27. ****************************************************************************/
  28.  
  29. /* List of possible enhancements
  30.     1. Insert a proper volume serial number (different from the original).
  31.         Ignore this difference when verifying.
  32.     2. Allow output drive != input.
  33.     3. Configure colors.
  34.     4. Use extended or expanded memory rather than a disk file.
  35.  */
  36.  
  37. #define LOGICAL        int
  38. #define FALSE            0
  39. #define TRUE            1
  40. #define START_CLOCK    0
  41. #define READ_CLOCK    1
  42. #define ERR                -1
  43. #define NO_ERR            0
  44.  
  45. #define BACKGROUND_COLOR    BLUE
  46. #define TEXT_COLOR            WHITE
  47. #define READ_INDICATOR        RED
  48. #define FORMAT_INDICATOR    MAGENTA
  49. #define WRITE_INDICATOR        GREEN
  50. #define VERIFY_INDICATOR    YELLOW
  51.  
  52. #define BYTES_PER_SECTOR    512
  53.  
  54. #define MAX_SECTORS    60
  55. #define BUFFER_SIZE    MAX_SECTORS*512
  56.  
  57. #define ERROR_ALERT()    {sound(45); delay(500);    nosound();}
  58. #define UP_N(n)    {gotoxy(1, wherey() - n);}
  59. #define UP_ONE_AND_CLEAR()    \
  60.     {cprintf("\r"); clreol(); gotoxy(1, wherey() - 1);    clreol();}
  61.  
  62. /* biosdisk() BIOS function cmd calls */
  63.  
  64. #define RESET_CONTROLLER    0
  65. #define READ_TRK                2
  66. #define WRITE_TRK                3
  67. #define VERIFY_TRK            4
  68. #define FORMAT_TRK            5
  69.  
  70. #define FLOPPY_360K 0
  71. #define FLOPPY_12MB 1
  72. #define FLOPPY_720K 2
  73. #define FLOPPY_144M 7
  74.  
  75. /* Prototypes for local routines
  76.  */
  77. char *getvolid(int dos_drive);
  78. void far hardset(void);
  79. void measure_speed(int function, char *thing_timed);
  80. void statline(int sectors, int color);
  81. int disk_format(int int13_drive, int drive_type);
  82. void erase_temp_file(void);
  83. LOGICAL disk_rw(int int13_drive, int action, int first_sector, int nsects,
  84.                      char *buffer);
  85. void reset_disk_controller(void);
  86. void disk_error_print(unsigned int error_code);
  87.  
  88. /* wsscopyd - copy a disk using another disk for temporary storage of
  89.     disk image.
  90.     usage: WSScopyd [options] d[:] [options]
  91.  
  92.     Options (case ignored, / or - switchchar allowed):
  93.         -B - beep when disk change is needed
  94.         -Cn - number of copies
  95.         -F - format target disk
  96.         -R fn - reuse saved file fn
  97.         -S fn - save disk file with name fn
  98.         -T - display time used
  99.         -V - verify by reading floppy and comparing to original data
  100.         -X1 - disk is single-sided, 10 sectors per track, 80 tracks
  101.         -X2 - disk is double-sided, 10 sectors per track, 80 tracks
  102.         -X3 - disk is RX-50 (like X1 but tracks after 1st two are 2:1 interleave)
  103.                 -X format source disks do not need to have a valid boot sector.
  104.                 Volume label will not be displayed during copying when -X is
  105.                 specified.
  106.  
  107.     Compile with compact or large model else allocation of buffers will fail.
  108.  
  109.     DESQView compatibility: DOS Buffers for EMS should be set larger than the
  110.     default value of 2K else run time will be excessive.  4K is the minimum
  111.     acceptable value, but 8K is better.  Performance continues to improve
  112.     up to at least 32K.  The -t option can be used to time operation with
  113.     different values.  The following read times were obtained on a 386/25:
  114.  
  115.      EMS buffer size    Seconds
  116.              2K            307.8      (default setting)
  117.              4K            161.6
  118.              8K             93.5
  119.             16K             76.3
  120.             32K             68.4
  121.         under DOS          59.4
  122.  
  123.     All screen output leaves a 2-character margin on left and right so that
  124.     everything will be visible even if there is a window border at the edge
  125.     of the screen.  The right margin also eliminates any worry about whether
  126.     writing in the last character position of the bottom row causes the screen
  127.     to scroll.
  128.  */
  129.  
  130. volatile int Hard_error;    /* Set to TRUE by critical error handler.  Note
  131.                                         that any call to absread or abswrite can
  132.                                         potentially set Hard_error, even if the
  133.                                         call succeeds after retrying. */
  134. int Fail_ignore = 3;            /* tell critical error handler to fail on error */
  135. int Tr_per_dsk = 40;
  136. int Sd_per_dsk = 1;
  137. int Sectors_per_track = 8;
  138. int Sectors_per_disk;
  139. LOGICAL Is_X;
  140. int X_type;
  141. void interrupt (*System_dpb)();
  142.  
  143. struct DPB
  144.     {
  145.     char spec1;            /* first specify byte */
  146.     char spec2;        /* second specify byte */
  147.     char stop_delay;    /* delay until motor turned off (ticks) */
  148.     char bps;            /* bytes per sector 0=128, 1=256, 2=512, 3=1024 */
  149.     char spt;            /* sectors per track */
  150.     char gap;            /* gap between sectors (2Ah for 5.25", 1Bh for 3.5") */
  151.     char data_l;        /* data length (ignored if bps is non-zero) */
  152.     char gap_l;            /* formatting gap length (50h for 5.25", 6ch for 3.5") */
  153.     char filler;        /* format filler byte (default F6h) */
  154.     char settle;        /* head settle time in milliseconds */
  155.     char start_time;    /* motor start time in 1/8 seconds */
  156.     } my_dpb;
  157.  
  158. char Tempfile[100];        /* file name for storage disk to be copied, global
  159.                                     so that exit routine can erase it if needed */
  160.  
  161. void main(int argc, char **argv)
  162.     {
  163.     char    huge *buffer,                /* buffer for data from floppy or save file */
  164.             huge *buffer2,            /* buffer for data from floppy when verifying */
  165.             *cfg_path,            /* full path to configuration file */
  166.             *cmp1,                /* pointer looping through buffer */
  167.             *cmp2,                /* pointer looping through buffer2 */
  168.             *openmode,            /* mode for opening disk file, read or update */
  169.             *temp_path,            /* TEMP or TMP environment variable */
  170.             *volname;            /* volume name or <none> */
  171.     FILE    *fp;                    /* file pointer for save file */
  172.     int   disk_cap,            /* disk drive capacity from cfg file, 1=360k, etc */
  173.             dos_drive,            /* drive number for DOS calls, A=0, B=1,... */
  174.          drive_type,            /* current drive type */
  175.             fat_sub,                /* 0 or 1 index into FAT mask and test arrays */
  176.             first_sec,            /* first sector to be read from floppy */
  177.             i,                        /* for loop index */
  178.             icopy,                /* counter for number of copies made */
  179.             int13_drive,        /* drive number for int 13h calls */
  180.             key,                    /* key hit in response to a prompt */
  181.             max_sectors_use,    /* number of sectors used in read/write buffer,
  182.                                         a multiple of the number of sectors per track */ 
  183.             n_alloc,                /* number of allocation units addressed by FAT */
  184.             ncopies,                /* number of copies requested */
  185.             ndrives,                /* number of drives defined in config file */
  186.             nread,                /* number of sectors to read in one call */
  187.             nver,                    /* number of sectors to verify in one call */
  188.             nwrite,                /* number of sectors to write in one call */
  189.             status,                /* status from ioctl check for removability or
  190.                                         from disk_rw call */
  191.             tot_sects;            /* number of sectors on source disk */
  192.     unsigned int    j,            /* for loop index */
  193.                         nbytes;    /* number of bytes to verify on one disk read */
  194.     LOGICAL  format,            /* if TRUE, format disks */
  195.                 have_drive,        /* set TRUE if command line specified drive */
  196.                 save_temp_file,/* if TRUE, temp file is saved */
  197.                 time,                /* if TRUE, display time used by each operation */
  198.                 use_beep,        /* if TRUE, sound alarm when disk swap is needed */
  199.                 use_old_file,    /* if TRUE, use an old temp file */
  200.                 verify;            /* if TRUE, verify copy by re-reading and comparing
  201.                                         with what should have been written */
  202.     char beep;                    /* control-g if alarm enabled, blank if not */
  203.     char    cfg_load_path[MAXPATH],        /* program load path with wsscopyd.cfg
  204.                                                     appended */
  205.             disk_letter[80],            /* scanf buffer for disk letter read */
  206.             disk_type[80],                /* scanf buffer for disk type read */
  207.             int13_number[80],            /* scanf buffer for int 13h disk number */
  208.